To allow users to sort items in a grid or table you need to do two things: Set the code to run when the sort button is pressed and update the display to reflect this.

Button / Icon Code

We will use a variable to store the sort value. To manipulate a variable within the context of a screen, we can use the UpdateContext function.  This will be triggered to the OnSelect method of the button or icon chosen.

UpdateContext({SortDescending1: !SortDescending1})

In the example above, the variable SortDescending1 is switched between True and False each time it is selected.

Grid / Table Code

To update the display, you need to edit the Items property of the grid or table.  When you attach the grid or table to a data source, the Items property will be set to the name of your data table (mine was called UltimateTweets. You will to update this to use the SortByColumns function. This function requires three parameters: The data being sorted (the original value), the column to be sorted by and finally the sort order.  For the sort order we will use an if function using the variable set by the button or icon previously.

SortByColumns(UltimateTweets,"WhenTweeted",If(SortDescending1,Ascending,Descending))

More details on these functions can be found at:

UpdateContext

SortByColumns

If